<?php
if (!function_exists('hideMiddleDigits')) {

    function hideMiddleDigits($phoneNumber)
    {
        // 确保输入的是一个有效的手机号，长度至少为10位
        if (strlen($phoneNumber) >= 10) {
            // 将中间四位替换为星号
            return substr($phoneNumber, 0, 3) . '****' . substr($phoneNumber, 7);
        } else {
            // 如果输入无效，返回原字符串或抛出错误
            return $phoneNumber;
        }
    }
}
if (!function_exists("isMobile")) {
    function isMobile()
    {
        $user_agent = $_SERVER['HTTP_USER_AGENT'];
        $mobile_agents = array ('iphone','android','phone','mobile','wap','netfront','java','opera mobi',
            'opera mini','ucweb','windows ce','symbian','series','webos','sony','blackberry','dopod',
            'nokia','samsung','palmsource','xda','pieplus','meizu','midp','cldc','motorola','foma',
            'docomo','up.browser','up.link','blazer','helio','hosin','huawei','novarra','coolpad',
            'techfaith','alcatel','amoi','ktouch','nexian','ericsson','philips','sagem','wellcom',
            'bunjalloo','maui','smartphone','iemobile','spice','bird','zte-','longcos','pantech',
            'gionee','portalmmm','jig browser','hiptop','benq','haier','^lct','320x320','240x320',
            '176x220','windows phone','cect','compal','ctl','lg','nec','tcl','daxian','dbtel','eastcom',
            'konka','kejian','lenovo','mot','soutec','sgh','sed','capitel','panasonic','sonyericsson',
            'sharp','panda','zte','acer','acoon','acs-','abacho','ahong','airness','anywhereyougo.com',
            'applewebkit/525','applewebkit/532','asus','audio','au-mic','avantogo','becker','bilbo',
            'bleu','cdm-','danger','elaine','eric','etouch','fly ','fly_','fly-','go.web','goodaccess',
            'gradiente','grundig','hedy','hitachi','htc','hutchison','inno','ipad','ipaq','ipod',
            'jbrowser','kddi','kgt','kwc','lg ','lg2','lg3','lg4','lg5','lg7','lg8','lg9','lg-','lge-',
            'lge9','maemo','mercator','meridian','micromax','mini','mitsu','mmm','mmp','mobi','mot-',
            'moto','nec-','newgen','nf-browser','nintendo','nitro','nook','obigo','palm','pg-',
            'playstation','pocket','pt-','qc-','qtek','rover','sama','samu','sanyo','sch-','scooter',
            'sec-','sendo','sgh-','siemens','sie-','softbank','sprint','spv','tablet','talkabout',
            'tcl-','teleca','telit','tianyu','tim-','toshiba','tsm','utec','utstar','verykool','virgin',
            'vk-','voda','voxtel','vx','wellco','wig browser','wii','wireless','xde','pad','gt-p1000');
        $ismobile = false;
        foreach ($mobile_agents as $device) {
            if (stristr($user_agent, $device)) {
                $ismobile = true;
                break;
            }
        }
        return $ismobile;
    }
}
if (!function_exists("ageInfo")) {
    function ageInfo($min, $max): string
    {
        if ($min <= 0 && $max <= 0) {
            return '年龄不限';
        }
        if ($min > 0 && $max > 0) {
            return "$min-{$max}岁";
        }
        if ($min <= 0 && $max > 0) {
            return "0-{$max}岁";
        }
        if ($min > 0 && $max <= 0) {
            return "{$min}岁以上";
        }
        return "";
    }
}

if (!function_exists("identifyQrCodeType")) {
//    function identifyQrCodeType($imagePath)
//    {
//        // 创建一个 ZBarCodeScanner 对象
//        $scanner = new ZBarCodeScanner();
//
//        // 解析二维码图像
//        $results = $scanner->scan($imagePath);
//
//        if (!empty($results)) {
//            foreach ($results as $result) {
//                $data = $result['data'];
//
//                // 判断二维码内容
//                if (strpos($data, 'wxp://') === 0) {
//                    if (strpos($data, 'type=group') !== false) {
//                        return '微信群二维码';
//                    } else {
//                        return '微信好友二维码';
//                    }
//                } elseif (strpos($data, 'https://mp.weixin.qq.com/') === 0) {
//                    return '微信公众号二维码';
//                }
//            }
//        }
//
//        return '未知类型';
//    }
}
